<template>
	<div>
		<!-- 导航区域 -->
		<el-breadcrumb separator="/">
			<el-breadcrumb-item :to="{ path: '/seller/welcome' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>用户管理</el-breadcrumb-item>
			<el-breadcrumb-item>我的</el-breadcrumb-item>
		</el-breadcrumb>
		<el-button type="infor" @click="showEditDialog">修改信息</el-button>
		<el-dialog title="修改信息" :visible.sync="editDialogVisible" width="30%">
			<!-- 修改用户表单 -->
			<span>
				<el-form label-width="65px" class="login_form" :model="upadteFormData">
					<el-form-item label="用户名" prop="name">
						<el-input placeholder="请输入用户名" v-model="upadteFormData.name"></el-input>
					</el-form-item>
		
					<el-form-item label="密 码" prop="password">
						<el-input placeholder="请输入密码" v-model="upadteFormData.password"></el-input>
					</el-form-item>

				</el-form>
			</span>
			<span slot="footer" class="dialog-footer">
				<el-button @click="editDialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="editDialogVisible = false;updateUser()">确 定</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				editDialogVisible: false,
				upadteFormData: {
					"name": "",
					"password": ""
				},
			}
		},
		methods:{
			async showEditDialog(id) {
				this.editDialogVisible = true;
				const data = {
					"token": window.sessionStorage.getItem("token"),
					"uid": this.userId
				}
				const {
					data: res
				} = await this.$http.get("userapi/detail/", {
					params: data
				});
				this.upadteFormData.name = res.user.name;
				this.upadteFormData.password = res.user.password;
				this.userId = res.user.id;
			},
			async updateUser() {
					let data = new FormData();
					data.append('name', this.upadteFormData.name);
					data.append('password', this.upadteFormData.password);
					data.append('uid', this.userId);
					// console.log(data);
					const token = window.sessionStorage.getItem("token");
					const {
						data: res
					} = await this.$http.post("userapi/login/?action=update&token=" + token, data);
					// console.log(res);
					if (res.status == 1000) {
						// console.log("修改成功");
						this.$message.success("修改用户成功");
					} else {
						this.$message.error("修改用户失败");
					}
			},
		}
	}
</script>

<style>
</style>
